import languageReducer from "./language/languageReducer"
import recommendProductsReducer from "./recommend-products/recommend-products-reducer"
import { actionLog } from "./middlewares/action-log"
import { productDetailSlice } from "./product-detail/slice"
import { combineReducers, configureStore } from "@reduxjs/toolkit"
import { productSearchSlice } from "./product-search/slice"
// 所有的reducers
const rootReducer = combineReducers({
  language: languageReducer,
  recommendProducts: recommendProductsReducer,
  productDetail: productDetailSlice.reducer,
  productSearch: productSearchSlice.reducer,
})
// const store = createStore(rootReducer, applyMiddleware(thunk, actionLog))
const store = configureStore({
  reducer: rootReducer,
  // middleware: (getDefaultMiddleware) => [...getDefaultMiddleware(), actionLog], // getDefaultMiddleware获取默认的中间件配置
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware().concat(actionLog),
  devTools: true,
})

export type RootState = ReturnType<typeof store.getState>

export default store
